<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Watch选项监控数据</title>
    <script type="text/javascript" src="../assets/js/vue.js"></script>
</head>
<body>
    <h1>Watch选项监控数据</h1>
    <hr>
    <div id="app">
        <p>今日温度: {{wendu}} 度</p>
        <p>穿衣建议：{{chuanyi}}</p>
        <p><button @click="shengao">升高温度</button><button @click="jiangdi">降低温度</button></p>
    </div>

    <script type="text/javascript">
        var chuanyiarr=['T恤短袖','夹克长裙','棉衣羽绒服']
        var app = new Vue({
            el:'#app',
            data:{
                wendu:14,
                chuanyi:'夹克长裙'
            },
            methods:{
                shengao:function(){
                    this.wendu+=5;
                },
                jiangdi:function(){
                    this.wendu-=5;
                }
            },
            // watch:{
            //     wendu:function(newVal,oldVal){
            //         if(newVal>=26){
            //             this.chuanyi=chuanyiarr[0];
            //         }else if(newVal<26&&newVal>0){
            //             this.chuanyi=chuanyiarr[1];
            //         }else{
            //             this.chuanyi=chuanyiarr[2];
            //         }
            //     }
            // }

        })
        app.$watch('wendu',function(newVal,oldVal){
            if(newVal>=26){
                this.chuanyi=chuanyiarr[0];
            }else if(newVal<26&&newVal>0){
                this.chuanyi=chuanyiarr[1];
            }else{
                this.chuanyi=chuanyiarr[2];
            }
        })
    </script>
</body>
</html>